package cn.elead.it.template.model.params;

import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

public class DemoParamArgumentResolver  implements HandlerMethodArgumentResolver {

	@Override
	public boolean supportsParameter(MethodParameter methodParameter) {
		return methodParameter.getParameterType().equals(DemoParam.class);
	}

	@Override
	public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
			NativeWebRequest nativeWebRequest, WebDataBinderFactory binderFactory) throws Exception {
		
		DemoParam param = new DemoParam();
		param.setName(nativeWebRequest.getParameter("user_name"));
		return param;
	}

}
